/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openjawtech.xscraper.web.dto;

import java.util.List;
import java.util.ArrayList;
import com.openjawtech.xscraper.schema.FlightsType;
import com.openjawtech.xscraper.schema.FlightType;
import java.util.Date;

/**
 *
 * @Created on 18-Mar-2009, 12:05:01
 * @author Wenbo.Sun
 */
public class FlightsDTO {
    private String departure;
    private String arrival;
    private List<FlightDTO> flights;

    public FlightsDTO() {
    }

    public FlightsDTO(String departure, String arrival, List<FlightDTO> flights) {
        this.departure = departure;
        this.arrival = arrival;
        this.flights = flights;
    }

    public FlightsDTO(FlightsType flightsType){
        this.departure = flightsType.getDeparture();
        this.arrival = flightsType.getArrival();
        this.flights = new ArrayList<FlightDTO>();
        for(FlightType flightType : flightsType.getFlightArray()){
            Date travelDate = flightType.getTravelDate().getTime();
            double price;
            if(flightType.isNilPrice() || flightType.getPrice() == null)
                price = -1;
            else
                price = flightType.getPrice().doubleValue();
            FlightDTO flight = new FlightDTO(travelDate, price);
            this.flights.add(flight);
        }
    }

    public String getDeparture() {
        return departure;
    }

    public void setDeparture(String departure) {
        this.departure = departure;
    }

    public String getArrival() {
        return arrival;
    }

    public void setArrival(String arrival) {
        this.arrival = arrival;
    }
    public List<FlightDTO> getFlights() {
        return flights;
    }

    public void setFlights(List<FlightDTO> flights) {
        this.flights = flights;
    }

    public void addFlight(FlightDTO flight){
        if(flights == null)
            flights = new ArrayList<FlightDTO>();
        flights.add(flight);
    }
}
